package algorithm.collection;


import java.util.Map;
import java.util.TreeMap;

/**
 * @Author: Hevery
 * @Description: 给定一个无序数组(奇数个)，找出该数组中的中位数，返回其对应的下标
 * @Date: Created on 2017/9/15
 * @Modified By:
 */
public class MiddleValue {
    public static void main(String[] args) {
        int[] a = {3,2,5,8,4,1,9};
        int middleValue = findMiddleValue(a);
        System.out.println(middleValue);

    }
    public static int findMiddleValue(int[] a){

        Map<Integer,Integer> map = new TreeMap<>();
        for(int i=0;i<a.length;i++){
            map.put(a[i],i);
        }
        for(Map.Entry<Integer,Integer> entry : map.entrySet()){
            System.out.println(entry.getKey()+"---"+entry.getValue());
        }
        int count = 0;
        for(Integer i : map.values()){
            if(count++ == a.length/2){
                return i;
            }
        }
        return -1;
    }
}
